package com.ourteam.product.api;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ourteam.frame.controller.AbstractCRUDServiceController;
import com.ourteam.product.ui.dao.ProductUIImageDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUIImageBean;
import com.ourteam.product.ui.service.IProductUIService;
import com.ourteam.product.ui.service.ProductUIServiceFactory;

@Controller
@CrossOrigin
@RequestMapping("/api/PRODUCT/UI/productUIImage")
public class ProductUIImageAPI extends
		AbstractCRUDServiceController<ProductUIImageDAOQueryBean, ProductUIImageSearchModel, ProductUIImageBean> {

	private static final IProductUIService PRODUCT_UI_SERVICE = ProductUIServiceFactory.getProductUIService();

	@Override
	protected ProductUIImageDAOQueryBean newQueryBean() {
		return new ProductUIImageDAOQueryBean();
	}

	@Override
	protected int queryCount(ProductUIImageDAOQueryBean queryBean) throws Exception {
		return PRODUCT_UI_SERVICE.queryProductUIImageCount(queryBean);
	}

	@Override
	protected ProductUIImageBean[] queryData(ProductUIImageDAOQueryBean queryBean) throws Exception {
		return PRODUCT_UI_SERVICE.queryProductUIImages(queryBean);
	}

	@Override
	protected void deleteData(long[] ids) throws Exception {
		PRODUCT_UI_SERVICE.deleteProductUIImages(ids);
	}

	@Override
	protected ProductUIImageBean getDataById(long id) throws Exception {
		return PRODUCT_UI_SERVICE.getProductUIImageById(id);
	}

	@Override
	protected void saveData(ProductUIImageBean dataBean) throws Exception {
		dataBean.setLastModifyTime(new Date());
		dataBean.setLastModifyUser(getLoginUserName());
		if (dataBean.getId() == 0) {
			PRODUCT_UI_SERVICE.addNewProductUIImage(dataBean);
		} else {
			PRODUCT_UI_SERVICE.modifyProductUIImage(dataBean);
		}
	}

}
